Skip to content

pin flatc version and regenerate stale code#8

Merged
Shane98c merged 2 commits intomainfrom
pin-flatc-version
Apr 2, 2026
Merged

pin flatc version and regenerate stale code#8
Shane98c merged 2 commits intomainfrom
pin-flatc-version

Conversation

@Shane98c
Copy link
Copy Markdown
Collaborator

@Shane98c Shane98c commented Apr 2, 2026

Fixes CI error on #7

Two issues fixed:

1. Stale generated code (broke CI): Upstream schema changes (new node_id/node_type fields on MoveOperation) were pulled in by prepare > sync-flatbuffers.sh but the generated TypeScript was never regenerated, so check:fbs failed.

2. No pinned flatc version (latent risk): CI installed one flatc version, local dev could use another. This didn't cause the current failure, but would cause hard-to-debug diffs if versions ever produced different output for the same schema.

Fix:

  • Regenerate TypeScript to match current upstream schemas
  • Add scripts/ensure-flatc.sh which pins flatc v25.12.19, auto-downloads to .bin/ if missing
  • generate:fbs and check:fbs npm scripts use the pinned version
  • Remove manual flatc install step from CI (the script handles it)

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a pinned flatc compiler versioning system to ensure consistent FlatBuffers code generation across different environments. It adds a script to automatically download the required binary, updates the project's build scripts, and includes updated generated TypeScript files. The review feedback focuses on enhancing the shell script's portability and reliability through better dependency checking and error handling, as well as ensuring a clean state during the FlatBuffers verification process.

@@ -0,0 +1,50 @@
#!/bin/bash
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using #!/usr/bin/env bash is more portable than #!/bin/bash, as it avoids hardcoding the path to the bash executable which may vary across different Unix-like systems.

Suggested change
#!/bin/bash
#!/usr/bin/env bash

# FLATC="$(./scripts/ensure-flatc.sh)"
# "$FLATC" -T -o ./src/format/flatbuffers --gen-all ./flatbuffers/all.fbs

set -euo pipefail
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's recommended to verify that the required tools (curl and unzip) are available before proceeding with the download and extraction process to provide a clearer error message if they are missing.

Suggested change
set -euo pipefail
set -euo pipefail
# Check dependencies
for cmd in curl unzip; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "error: $cmd is required but not installed." >&2
exit 1
fi
done

trap 'rm -rf "$TMPDIR"' EXIT

echo "Downloading flatc v${FLATC_VERSION}..." >&2
curl -sL "$URL" -o "$TMPDIR/flatc.zip"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Adding the -f flag to curl ensures the script fails if the download returns an HTTP error code (like 404). Additionally, consider verifying the checksum of the downloaded binary to ensure its integrity and security.

Suggested change
curl -sL "$URL" -o "$TMPDIR/flatc.zip"
curl -fsSL "$URL" -o "$TMPDIR/flatc.zip"

package.json Outdated
"generate:fbs": "flatc -T -o ./src/format/flatbuffers --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs ./src/format/flatbuffers && prettier --write src/format/flatbuffers/generated",
"check:fbs": "flatc -T -o /tmp/fbs-check --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs /tmp/fbs-check && prettier --write /tmp/fbs-check/generated && diff -r /tmp/fbs-check/generated src/format/flatbuffers/generated"
"generate:fbs": "FLATC=\"$(./scripts/ensure-flatc.sh)\" && \"$FLATC\" -T -o ./src/format/flatbuffers --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs ./src/format/flatbuffers && prettier --write src/format/flatbuffers/generated",
"check:fbs": "FLATC=\"$(./scripts/ensure-flatc.sh)\" && \"$FLATC\" -T -o /tmp/fbs-check --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs /tmp/fbs-check && prettier --write /tmp/fbs-check/generated && diff -r /tmp/fbs-check/generated src/format/flatbuffers/generated"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Cleaning the /tmp/fbs-check directory before running flatc ensures that the comparison is performed against a fresh set of generated files, preventing false positives from stale files left over from previous runs.

Suggested change
"check:fbs": "FLATC=\"$(./scripts/ensure-flatc.sh)\" && \"$FLATC\" -T -o /tmp/fbs-check --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs /tmp/fbs-check && prettier --write /tmp/fbs-check/generated && diff -r /tmp/fbs-check/generated src/format/flatbuffers/generated"
"check:fbs": "rm -rf /tmp/fbs-check && mkdir -p /tmp/fbs-check && FLATC=\"$(./scripts/ensure-flatc.sh)\" && \"$FLATC\" -T -o /tmp/fbs-check --gen-all ./flatbuffers/all.fbs && node scripts/postgen-fbs.cjs /tmp/fbs-check && prettier --write /tmp/fbs-check/generated && diff -r /tmp/fbs-check/generated src/format/flatbuffers/generated"

@Shane98c Shane98c merged commit 8f15245 into main Apr 2, 2026
6 checks passed
@Shane98c Shane98c deleted the pin-flatc-version branch April 2, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant